package com.hm.PushCaseService.control;

import com.hm.PushCaseService.framework.service.base.IBaseService;
import com.hm.PushCaseService.framework.service.session.ISessionService;
import com.hm.PushCaseService.pojo.response.SessionResponse;
import jakarta.servlet.http.HttpServletRequest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;


@RestController
@RequestMapping(value = "/main", produces = {"application/json;charset=UTF-8"})
public class PCS_000_000_000<T> {

    private static final Logger logger = LoggerFactory.getLogger(PCS_000_000_000.class);

    private final IBaseService<SessionResponse> iBaseService;

    private final ISessionService iSessionService;

    public PCS_000_000_000(IBaseService<SessionResponse> iBaseService, ISessionService iSessionService) {
        this.iBaseService = iBaseService;
        this.iSessionService = iSessionService;
    }

    //获取session接口
    @PostMapping(value = "/000_000_000")
    public String doPost(HttpServletRequest request) {
        //session基本处理
        HashMap<String, String> resMap = iSessionService.handleSession(request);
        String state = resMap.get("state");
        String msg = resMap.get("msg");
        String secretKey = resMap.get("secretKey");
        if (!state.equals("000")) {
            return iBaseService.generateFail(msg);
        }
        //封装响应体
        SessionResponse response = new SessionResponse();
        response.sessionId = iSessionService.generateSessionId();
        return iBaseService.generateSucceed(secretKey, response);
    }

}
